<?php

/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
*/
/**
 * Description of RefuseController
 *
 * @author hoangle
 */
class Backend_ClientController extends Zend_Controller_Action {

//put your code here
    public function init() {
        $this->_helper->layout->setLayout('backend');
        Service_Account::checkLogin(2);
    }
    
    public function index() {
        $this->_forward('get');
    }
    
    public function balanceAction() {
        if ($this->_request->isPost()) {
            $arrData = $this->_request->getPost();

            $arrAccount = NULL;
            $arrBalanceUser = NULL;

            //Get user info
            $arrAccount = Service_Model::factory('User', 'getAccountByUserName', $arrData['username'], 'backend');
            if (!empty($arrAccount)) {
                //Get balance of user
                $arrBalanceUser = Service_Model::factory('Balance', 'getBalanceByUserId', $arrAccount['userid'], 'backend');
            }
            $this->view->arrUser = $arrAccount;
            $this->view->arrBalance = $arrBalanceUser;
        }
    }
    
    public function ajaxaddcreditAction() {
        if ($this->_request->isPost()) {
            $arrData = $this->_request->getPost();
            if (!empty($arrData)) {
                $result = Service_Model::factory('Balance', 'updateCreditByUserId', $arrData, 'backend');
                if($result) {
                    echo 'true';
                }
                else {
                    echo 'false';
                }
            }
            else {
                echo 'false';
            }
        }
        exit;
    }

    public function ajaxsubcreditAction() {
        if ($this->_request->isPost()) {
            $arrData = $this->_request->getPost();
            if (!empty($arrData)) {
                $result = Service_Model::factory('Balance', 'decreaseCreditByUserId', $arrData, 'backend');
                if($result) {
                    echo 'true';
                }
                else {
                    echo 'false';
                }
            }
            else {
                echo 'false';
            }
        }
        exit;
    }

    
}

?>
